/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import dao.QuyDinhDAO;
import java.text.DateFormat;
import java.text.Format;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFormattedTextField;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import pojo.Quydinh;

/**
 *
 * @author sangnguyen
 */
public class JInternalFrameQuyDinh extends javax.swing.JInternalFrame {

    /**
     * Creates new form JInternalFrameQuyDinh
     */
    private DefaultTableModel tbModel;
    private List<Quydinh> ls;
    public void XoaTrang(){
        this.jTextFieldMaQuyDinh.setText("");
        this.jTextFieldTenQuyDinh.setText("");
        this.jTextFieldGiaTriMoi.setText("");
        this.jTextFieldGiaTriCu.setText("");
        this.jTextAreaGhiChu.setText("");
        this.jFormattedTextFieldNgayCapNhatCu.setText("");
        
    }
    public JInternalFrameQuyDinh() {
        initComponents();
        
        this.jFormattedTextFieldNgayHienTai.setValue(Calendar.getInstance().getTime());
        this.tbModel = new DefaultTableModel(){
            public boolean isCellEditable(int rowIndex, int colIndex) {
                return false; 
        }
        };
        Format formatter = new SimpleDateFormat("dd-MM-yyyy");
        this.tbModel.addColumn("STT");
        //this.tbModel.addColumn("ID");
        this.tbModel.addColumn("Mã quy định");                
        this.tbModel.addColumn("Tên quy định");                
        this.tbModel.addColumn("Giá trị");                
        this.tbModel.addColumn("Ngày cập nhật");                
        this.tbModel.addColumn("Ghi chú");          
        ls = QuyDinhDAO.SelectAllQuydinh();
        for(int i=0;i<ls.size();i++)
        {
            Vector vt = new Vector();            
            vt.add(i+1);
            vt.add(ls.get(i).getMaqd());
            vt.add(ls.get(i).getTenqd());
            vt.add(ls.get(i).getGiatri());
            vt.add(formatter.format(ls.get(i).getNgaycapnhat()));
            vt.add(ls.get(i).getGhichu());
            tbModel.addRow(vt);
        }        
        this.jTableQuyDinh.setModel(tbModel);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldTenQuyDinh = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldGiaTriCu = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableQuyDinh = new javax.swing.JTable();
        jLabel6 = new javax.swing.JLabel();
        jTextFieldMaQuyDinh = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextAreaGhiChu = new javax.swing.JTextArea();
        jButtonThem = new javax.swing.JButton();
        jButtonCapNhat = new javax.swing.JButton();
        jButtonXoa = new javax.swing.JButton();
        jButtonXoaTrang = new javax.swing.JButton();
        jButtonThoat = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jTextFieldGiaTriMoi = new javax.swing.JTextField();
        jFormattedTextFieldNgayCapNhatCu = new javax.swing.JFormattedTextField();
        jFormattedTextFieldNgayHienTai = new javax.swing.JFormattedTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();

        setClosable(true);
        setForeground(java.awt.Color.white);
        setIconifiable(true);
        setTitle("Quy Định");
        setToolTipText("Màn hình quy định");
        setAutoscrolls(true);
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setDoubleBuffered(true);
        setMaximumSize(new java.awt.Dimension(700, 650));
        setName(""); // NOI18N
        setPreferredSize(new java.awt.Dimension(610, 700));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Quy Định");

        jLabel2.setText("Tên quy định");

        jLabel3.setText("Giá trị cũ");

        jTextFieldGiaTriCu.setEditable(false);

        jLabel4.setText("Ngày cập nhật cũ");

        jLabel5.setText("Giá trị mới");

        jTableQuyDinh.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jTableQuyDinh.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jTableQuyDinh.setToolTipText("");
        jTableQuyDinh.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableQuyDinhMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTableQuyDinh);

        jLabel6.setText("Mã quy định");

        jLabel7.setText("Ghi chú");

        jTextAreaGhiChu.setColumns(20);
        jTextAreaGhiChu.setRows(4);
        jTextAreaGhiChu.setTabSize(4);
        jScrollPane2.setViewportView(jTextAreaGhiChu);

        jButtonThem.setText("Thêm");
        jButtonThem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonThemActionPerformed(evt);
            }
        });

        jButtonCapNhat.setText("Cập nhật");
        jButtonCapNhat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCapNhatActionPerformed(evt);
            }
        });

        jButtonXoa.setText("Xóa");
        jButtonXoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonXoaActionPerformed(evt);
            }
        });

        jButtonXoaTrang.setText("Xóa trắng");
        jButtonXoaTrang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonXoaTrangActionPerformed(evt);
            }
        });

        jButtonThoat.setText("Thoát");
        jButtonThoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonThoatActionPerformed(evt);
            }
        });

        jLabel8.setText("Ngày hiện tại");

        jFormattedTextFieldNgayCapNhatCu.setEditable(false);
        jFormattedTextFieldNgayCapNhatCu.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd-MM-yyyy"))));

        jFormattedTextFieldNgayHienTai.setEditable(false);
        jFormattedTextFieldNgayHienTai.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd-MM-yyyy"))));

        jLabel9.setText("(dd-MM-yyyy)");

        jLabel10.setText("(dd-MM-yyyy)");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jButtonThem, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jButtonCapNhat, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(jButtonXoa, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(jButtonXoaTrang, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(jButtonThoat, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel3)
                                        .addComponent(jLabel5)
                                        .addComponent(jLabel7))
                                    .addGap(29, 29, 29)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                            .addComponent(jTextFieldGiaTriMoi)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel2)
                                                .addComponent(jLabel4)
                                                .addComponent(jLabel8))
                                            .addGap(37, 37, 37)
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addComponent(jTextFieldTenQuyDinh, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGroup(layout.createSequentialGroup()
                                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(jFormattedTextFieldNgayCapNhatCu)
                                                        .addComponent(jFormattedTextFieldNgayHienTai))
                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(jLabel9)
                                                        .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING)))))
                                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 491, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextFieldGiaTriCu, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldMaQuyDinh, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(241, 241, 241))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jTextFieldMaQuyDinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldTenQuyDinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldGiaTriCu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jFormattedTextFieldNgayCapNhatCu)
                    .addComponent(jLabel9))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jLabel8)
                            .addComponent(jTextFieldGiaTriMoi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jFormattedTextFieldNgayHienTai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10))))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(jLabel7))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(16, 16, 16)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonCapNhat)
                    .addComponent(jButtonThem)
                    .addComponent(jButtonXoa)
                    .addComponent(jButtonXoaTrang)
                    .addComponent(jButtonThoat))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonThemActionPerformed
        // TODO add your handling code here:
        if(this.jTextFieldMaQuyDinh.getText().isEmpty()==true || this.jTextFieldTenQuyDinh.getText().isEmpty()==true || this.jTextFieldGiaTriMoi.getText().isEmpty()==true){
            JOptionPane.showMessageDialog(this, "Chưa nhập đầy đủ thông tin");
            return;
        }
        else
        {
            Format formatter = new SimpleDateFormat("dd-MM-yyyy");
            Quydinh obj = new Quydinh();
            obj.setMaqd(this.jTextFieldMaQuyDinh.getText());
            obj.setTenqd(this.jTextFieldTenQuyDinh.getText());
            
            obj.setGiatri(this.jTextFieldGiaTriMoi.getText());
            obj.setGhichu(this.jTextAreaGhiChu.getText());
            Calendar cal = Calendar.getInstance();            
            Date day = cal.getTime();
            obj.setNgaycapnhat(day);
            obj.setTinhtrang(1);
            if(QuyDinhDAO.InsertQuydinh(obj)){
                JOptionPane.showMessageDialog(this, "Thêm thành công!");                                    
                Vector vt = new Vector();            
                vt.add(tbModel.getRowCount()+1);
                vt.add(obj.getMaqd());
                vt.add(obj.getTenqd());
                vt.add(obj.getGiatri());
                vt.add(formatter.format(obj.getNgaycapnhat()));
                vt.add(obj.getGhichu());
                tbModel.addRow(vt);            
                ls.add(obj);
                this.jTableQuyDinh.setModel(tbModel);
            }
            else{
                JOptionPane.showMessageDialog(this, "Thêm thất bại! (trùng mã qui định)");                                    
                return;
            }
        }                
    }//GEN-LAST:event_jButtonThemActionPerformed

    private void jTableQuyDinhMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableQuyDinhMouseClicked
        // TODO add your handling code here:
        this.XoaTrang();
        try{                   
            int dong = this.jTableQuyDinh.getSelectedRow();
            if(dong>=0){                            
                String maQD = "";
                String tenQD = "";
                String giatriQD = "";
                String ngayQD = "";
                String ghiChuQD = "";
                if(this.jTableQuyDinh.getValueAt(dong,1).toString().isEmpty()==false){
                    maQD = this.jTableQuyDinh.getValueAt(dong,1).toString();
                    this.jTextFieldMaQuyDinh.setText(maQD);
                }
                
                if(this.jTableQuyDinh.getValueAt(dong,2).toString().isEmpty()==false){
                    tenQD = this.jTableQuyDinh.getValueAt(dong,2).toString();
                    this.jTextFieldTenQuyDinh.setText(tenQD);
                }
                    
                if(this.jTableQuyDinh.getValueAt(dong,3).toString().isEmpty()==false){
                    giatriQD = this.jTableQuyDinh.getValueAt(dong,3).toString();      
                    this.jTextFieldGiaTriCu.setText(giatriQD);
                }
                ngayQD = this.jTableQuyDinh.getValueAt(dong,4).toString();
                //String [] arrDate = ngayQD.split("-");
                //Date ngay = new Date(Integer.parseInt(arrDate[0]), Integer.parseInt(arrDate[1]), Integer.parseInt(arrDate[2]));        
                
                SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
                Date ngay =formatter.parse(ngayQD);
                if(this.jTableQuyDinh.getValueAt(dong,5).toString().isEmpty()==false){
                    ghiChuQD = this.jTableQuyDinh.getValueAt(dong,5).toString();                
                    this.jTextAreaGhiChu.setText(ghiChuQD);
                }                                
                this.jFormattedTextFieldNgayCapNhatCu.setValue(ngay);            
            }
        }
        catch (Exception ex){
            //throw ex;
        }
        
    }//GEN-LAST:event_jTableQuyDinhMouseClicked

    private void jButtonThoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonThoatActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jButtonThoatActionPerformed

    private void jButtonCapNhatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCapNhatActionPerformed
        try {
            // TODO add your handling code here:
            int confirm = JOptionPane.showConfirmDialog(this, "Bạn có muốn cập nhật quy định này không?", "Xác nhận", JOptionPane.YES_NO_OPTION);
            if(confirm == JOptionPane.YES_OPTION){
                int dong = this.jTableQuyDinh.getSelectedRow();            
                Quydinh obj = ls.get(dong);
                obj.setMaqd(this.jTextFieldMaQuyDinh.getText());
                obj.setTenqd(this.jTextFieldTenQuyDinh.getText());        
                obj.setGiatri(this.jTextFieldGiaTriMoi.getText());
                obj.setGhichu(this.jTextAreaGhiChu.getText());
                Calendar cal = Calendar.getInstance();
                Date day = cal.getTime();
                obj.setNgaycapnhat(day);
                obj.setTinhtrang(1);
                if(QuyDinhDAO.UpdateQuydinh(obj)){                    
                    SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
                    //Date dt = new Date(day.getYear()+1900, day.getMonth()+1, day.getDate());
                    tbModel.setValueAt(obj.getMaqd(), dong, 1);
                    tbModel.setValueAt(obj.getTenqd(), dong, 2);
                    tbModel.setValueAt(obj.getGiatri(), dong, 3);
                    tbModel.setValueAt(formatter.format(day), dong, 4);
                    tbModel.setValueAt(obj.getGhichu(), dong, 5);
                }
                else{
                    JOptionPane.showMessageDialog(this, "Cập nhật thất bại");
                    return;
                }
            }
            else
                return;
        } catch (Exception ex){
            try {
                throw ex;
            } catch (Exception ex1) {
                Logger.getLogger(JInternalFrameQuyDinh.class.getName()).log(Level.SEVERE, null, ex1);
            }
        }

    }//GEN-LAST:event_jButtonCapNhatActionPerformed

    private void jButtonXoaTrangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonXoaTrangActionPerformed
        // TODO add your handling code here:
        this.XoaTrang();
    }//GEN-LAST:event_jButtonXoaTrangActionPerformed

    private void jButtonXoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonXoaActionPerformed
        // TODO add your handling code here:
        try {
            // TODO add your handling code here:
            int confirm = JOptionPane.showConfirmDialog(this, "Bạn có muốn xóa quy định này không?", "Xác nhận", JOptionPane.YES_NO_OPTION);
            if(confirm == JOptionPane.YES_OPTION){
                int dong = this.jTableQuyDinh.getSelectedRow();            
                Quydinh obj = ls.get(dong);
                obj.setMaqd(this.jTextFieldMaQuyDinh.getText());
                obj.setTenqd(this.jTextFieldTenQuyDinh.getText());        
                obj.setGiatri(this.jTextFieldGiaTriMoi.getText());
                obj.setGhichu(this.jTextAreaGhiChu.getText());
                Calendar cal = Calendar.getInstance();
                Date day = cal.getTime();
                obj.setNgaycapnhat(day);
                obj.setTinhtrang(0);
                if(QuyDinhDAO.DeleteQuydinh(obj)){
                    JOptionPane.showMessageDialog(this, "Đã xóa");
                    tbModel.removeRow(dong);            
                    ls.remove(dong);
                    for(int i = 0;i<this.tbModel.getRowCount();i++)
                    {                
                        this.tbModel.setValueAt(i+1, i, 0);
                    }
                    this.jTableQuyDinh.setModel(tbModel);
                }
                else{
                    JOptionPane.showMessageDialog(this, "Không xóa được");
                    return;
                }
                    
            //this.jTableQuyDinh.setModel(this.tbModel);
            }
            else
                return;
        } catch (Exception ex){
            try {
                throw ex;
            } catch (Exception ex1) {
                Logger.getLogger(JInternalFrameQuyDinh.class.getName()).log(Level.SEVERE, null, ex1);
            }
        }
    }//GEN-LAST:event_jButtonXoaActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCapNhat;
    private javax.swing.JButton jButtonThem;
    private javax.swing.JButton jButtonThoat;
    private javax.swing.JButton jButtonXoa;
    private javax.swing.JButton jButtonXoaTrang;
    private javax.swing.JFormattedTextField jFormattedTextFieldNgayCapNhatCu;
    private javax.swing.JFormattedTextField jFormattedTextFieldNgayHienTai;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTableQuyDinh;
    private javax.swing.JTextArea jTextAreaGhiChu;
    private javax.swing.JTextField jTextFieldGiaTriCu;
    private javax.swing.JTextField jTextFieldGiaTriMoi;
    private javax.swing.JTextField jTextFieldMaQuyDinh;
    private javax.swing.JTextField jTextFieldTenQuyDinh;
    // End of variables declaration//GEN-END:variables
}
